home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1729 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: realloc->free?
  5. Date: Tue, 16 Jan 96 16:19:37 GMT
  6. Organization: none
  7. Message-ID: <821809177snz@genesis.demon.co.uk>
  8. References: <4daa2e$oh5@axe.netdoor.com> <4de8uv$48j@bs33n.staffs.ac.uk>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4de8uv$48j@bs33n.staffs.ac.uk>
  15.            cm4bctrd@bs47c.staffs.ac.uk "Wildfire" writes:
  16.  
  17. >: b = realloc(a, 100);
  18.  
  19. ...
  20.  
  21. >If you think about it, there is no need for realloc() to move the *start* 
  22. >of the allocated memory - it may need to make a link between the end of 
  23. >the original memory block and the start of an extension block, but that's 
  24. >different.
  25.  
  26. What do you mean by 'make a link'? The block of memory returned by realloc
  27. must be contiguous so that, for example, you can treat it like an array
  28. and access all elements using pointer arithmetic.
  29.  
  30. >So b is either going to be NULL or a.
  31.  
  32. Never assume in a program that b will equal a - it can and does change in
  33. implementations even when the allocation size is being reduced (some
  34. allcation schemes will allocate from different internal tables depending
  35. on the allocation size, a realloc may require a shift from one table
  36. to another on any change in size).
  37.  
  38. >realloc() does no free()ing, as far as I know, since the contents of 
  39. >memory are unchanged.
  40.  
  41. It releases unneeded space when you redude the allocation size and is
  42. equivalent to free when the allocation size is zero.
  43.  
  44. -- 
  45. -----------------------------------------
  46. Lawrence Kirby | fred@genesis.demon.co.uk
  47. Wilts, England | 70734.126@compuserve.com
  48. -----------------------------------------
  49.